// reservation/write-off/write-off.js
import api from '../../utils/api.js';
import network from '../../utils/network.js';
import formatDate from '../../utils/format_date';

Page({

    /**
     * 页面的初始数据
     */
    data: {
        visible: false,
        details: {},
        bookingTime: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        network.getJson(api.getOrder, {
            id: options.id
        }).then(res => {
            let details = res.data;
            let times = details.bookingTimes;
            for (let j = 0; j < times.length; j++) {
                details.bookingTimes[j].format = formatDate.formatWeek(times[j].startTime, times[j].endTime);
            }
            details.bookingTimes = times;
            this.setData({
                details,
                bookingTime: times[0]
            })
        })
    },

    onVisibleChange(e) {
        this.setData({
            visible: e.detail.visible,
        });
    },

    tranTap() {
        this.setData({
            visible: true,
        });
    },

    chooseCode(e) {
        let idx = e.currentTarget.dataset.idx;
        this.setData({
            visible: false,
            bookingTime: this.data.details.bookingTimes[idx]
        })
    },

    callPhone() {
        wx.makePhoneCall({
          phoneNumber: this.data.details.usersDO.mobile
        })
    },

    goPay() {
        wx.navigateTo({
          url: '/home/pay/pay?details=' + encodeURIComponent(JSON.stringify(this.data.details))
        })
      },
})